﻿namespace ExamV5.StudyInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class BookTree : Page
    {
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        private PublicFun publicFun_0 = new PublicFun();
        protected TreeView TreeSubject;

        private void method_0(string string_0, TreeNode treeNode_0, string string_1, string string_2)
        {
            TreeNode node;
            node = new TreeNode {
                Value = string_1,
                Text = string_0,
                ToolTip = string_2,
                NavigateUrl = string.Concat(new object[] { "BookDoc.aspx?SubjectID=", this.int_0, "&ID=", string_1 }),
                Target = "BookmainFrame"
            };
            if (string_1 == "0")
            {
                this.TreeSubject.Nodes.Add(node);
                treeNode_0.Expanded = true;
            }
            else
            {
                treeNode_0.ChildNodes.Add(node);
                treeNode_0.Expanded = true;
            }
            string cmdText = string.Concat(new object[] { "select ID,ItemName,UPID from BookItem where SubjectID=", this.int_0, " and UPID='", string_2, "' order by SortInfo,id " });
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlCommand command = new SqlCommand(cmdText, connection);
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                this.method_0(reader["ItemName"].ToString(), node, reader["ID"].ToString(), reader["ID"].ToString());
            }
            reader.Close();
            connection.Close();
            connection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---查看电子教材";
                this.int_0 = Convert.ToInt32(base.Request["SubjectID"].ToString());
                if (!base.IsPostBack)
                {
                    this.TreeSubject.Nodes.Clear();
                    TreeNode node = new TreeNode();
                    string values = this.publicFun_0.GetValues(string.Concat(new object[] { "select SubjectName from BookInfo a,TypeList b where a.SubjectTypeID=b.ID and a.ID=", this.int_0, " and (b.BrowUserCode like '%,所有人员,%' or b.BrowUserCode like '%,", this.httpCookie_0.Value, ",%'  or b.BrowDeptID like '%,", this.httpCookie_3.Value, ",%' or b.BrowDeptName like '%,所有部门,%' )" }), "SubjectName");
                    if (!(values.Trim() == ""))
                    {
                        this.method_0(values, node, "0", "0");
                    }
                    else
                    {
                        base.Response.Write("<script>alert('此电子教材您暂无浏览权限！')</script>");
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

